<?php
include "definitions.php";



class Functions{
	
		function __construct(){
		}
		
		function __destruct(){
		}
		
    //Pripojenie k DB
		function connect_to_DB(){
        	mysql_connect(server, user, password) or die(server_conn_err.": " . mysql_error());
        	mysql_select_db(database) or die(db_conn_err.": ".database);
          //UTF8
        	mysql_query("SET names UTF8");
		}
		
//		vyber pouzivatela z DB
		function select_login($what,$table,$login,$pass){
      $query = mysql_query("SELECT ".$what." FROM ".$table." WHERE login='".$login."' AND heslo='".md5($pass)."'");
      return $query;
		}

		/*function select_student(){
      $query = mysql_query("SELECT * FROM user WHERE role='student'");
      return $query;
    }	*/
    	
		function select_student($id){
      if($id!="") $idq=" AND id='".$id."'"; else $idq="";
      return mysql_query("SELECT * FROM pouzivatel WHERE rola_id=1 ".$idq);
    }	
		function select_ucitel($id){
      if($id!="") $idq=" AND id='".$id."'"; else $idq="";
      return mysql_query("SELECT * FROM pouzivatel WHERE rola_id=2 ".$idq);
    }	
		function select_zadanie($id){
      if($id!="") $idq=" WHERE zadanie_id='".$id."'"; else $idq="";
      return mysql_query("SELECT * FROM zadanie ".$idq);
    }	
    
		function change_student($id,$name,$email){
      $query = mysql_query("UPDATE pouzivatel SET meno='".$name."' , email='".$email."' WHERE pouzivatel_id='".$id."'");
      return $query;
    }
    
		function select_consult($id){
      if($id!="") $idq=" WHERE konzultacia_id='".$id."'"; else $idq="";
      return mysql_query("SELECT * FROM  konzultacie ".$idq);
    }


}	
?>